﻿using Admin.Database.Enums;
using Admin.Database.Model;
using Mapster;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Admin.Application.DynamicApi.System.Menu.Dto
{
	/// <summary>
	/// 系统菜单返回结果
	/// </summary>
	public class MenuOutput
	{
		/// <summary>
		/// Id
		/// </summary>
		public long id { get; set; }

		/// <summary>
		/// 父Id
		/// </summary>
		public long pid { get; set; }

		/// <summary>
		/// 菜单类型（0目录 1菜单 2按钮）
		/// </summary>
		public MenuTypeEnum type { get; set; }

		/// <summary>
		/// 名称
		/// </summary>
		public string name { get; set; }

		/// <summary>
		/// 路由地址
		/// </summary>
		public string path { get; set; }

		/// <summary>
		/// 组件路径
		/// </summary>
		public string component { get; set; }

		/// <summary>
		/// 权限标识
		/// </summary>
		public string permission { get; set; }

		/// <summary>
		/// 重定向
		/// </summary>
		public string redirect { get; set; }

		/// <summary>
		/// 排序
		/// </summary>
		public int orderNo { get; set; }

		/// <summary>
		/// 状态
		/// </summary>
		public StatusEnum status { get; set; }

		/// <summary>
		/// 备注
		/// </summary>
		public string remark { get; set; }

		/// <summary>
		/// 创建时间
		/// </summary>
		public virtual DateTime createTime { get; set; }

		/// <summary>
		/// 更新时间
		/// </summary>
		public virtual DateTime updateTime { get; set; }

		/// <summary>
		/// 创建者姓名
		/// </summary>
		public virtual string createUserName { get; set; }

		/// <summary>
		/// 修改者姓名
		/// </summary>
		public virtual string updateUserName { get; set; }

		/// <summary>
		/// 菜单Meta
		/// </summary>
		public SysMenuMeta meta { get; set; }

		/// <summary>
		/// 菜单子项
		/// </summary>
		public List<MenuOutput> children { get; set; }
	}

	/// <summary>
	/// 菜单Meta配置
	/// </summary>
	public class SysMenuMeta
	{
		/// <summary>
		/// 标题
		/// </summary>
		public string title { get; set; }

		/// <summary>
		/// 图标
		/// </summary>
		public string icon { get; set; }

		/// <summary>
		/// 是否内嵌
		/// </summary>
		public bool isIframe { get; set; }

		/// <summary>
		/// 外链链接
		/// </summary>
		public string isLink { get; set; }

		/// <summary>
		/// 是否隐藏
		/// </summary>
		public bool isHide { get; set; }

		/// <summary>
		/// 是否缓存
		/// </summary>
		public bool isKeepAlive { get; set; }

		/// <summary>
		/// 是否固定
		/// </summary>
		public bool isAffix { get; set; }
	}

	/// <summary>
	/// 配置菜单对象映射
	/// </summary>
	public class SysMenuMapper : IRegister
	{
		public void Register(TypeAdapterConfig config)
		{
			config.ForType<SysMenu, MenuOutput>()
				.Map(t => t.meta.title, o => o.Title)
				.Map(t => t.meta.icon, o => o.Icon)
				.Map(t => t.meta.isIframe, o => o.IsIframe)
				.Map(t => t.meta.isLink, o => o.OutLink)
				.Map(t => t.meta.isHide, o => o.IsHide)
				.Map(t => t.meta.isKeepAlive, o => o.IsKeepAlive)
				.Map(t => t.meta.isAffix, o => o.IsAffix)
				.Map(t =>t.children, o => o.Children);
		}
	}
}
